/*
Copyright 2000-2011 Francois de Bertrand de Beuvron

This file is part of CoursBeuvron.

CoursBeuvron is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

CoursBeuvron is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with CoursBeuvron.  If not, see <http://www.gnu.org/licenses/>.
 */
package fr.insa.beuvron.tps.m2.dessin2DV3.gui;

import fr.insa.beuvron.tps.m2.dessin2DV3.Point;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 * Un petit formulaire pour entrer les caractéristiques d'un point.
 * Attention : ce formulaire n'est pas idéal : il place la ligne "abscisse" en haut,
 * et la ligne "ordonnee" en bas d'un BorderLayout. Si j'agrandi le panel, l'espace
 * va se créer entre ces deux lignes, ce qui ne sera pas très beau.
 * De plus, cette façon de faire un formulaire n'est pas extensible à plus de deux
 * lignes.
 * Pour un principe de disposition un peu plus satisfaisant, voir PointPanel2
 * @author francois
 */
public class PointPanel extends JPanel{
    
    public JTextField jtfPx;
    public JLabel jlPx;
    public JPanel jpPx;
    
    public JTextField jtfPy;
    public JLabel jlPy;
    public JPanel jpPy;
    
    public PointPanel() {
        this.setLayout(new BorderLayout());
        this.jpPx = new JPanel(new BorderLayout());
        this.jlPx = new JLabel("abscisse : ");
        this.jpPx.add(this.jlPx,BorderLayout.WEST);
        this.jtfPx = new JTextField(10);
        this.jpPx.add(this.jtfPx,BorderLayout.CENTER);
        this.add(this.jpPx,BorderLayout.NORTH);
        
        this.jpPy = new JPanel(new BorderLayout());
        this.jlPy = new JLabel("ordonnée : ");
        this.jpPy.add(this.jlPy,BorderLayout.WEST);
        this.jtfPy = new JTextField(10);
        this.jpPy.add(this.jtfPy,BorderLayout.CENTER);
        this.add(this.jpPy,BorderLayout.SOUTH);
    }

    public void modifieEditeur(Point p) {
        this.jtfPx.setText("" + p.getAbscisse());
        this.jtfPy.setText("" + p.getOrdonnee());
    }
    
    public void modifieObjet(Point p) {
        p.setAbscisse(Double.parseDouble(this.jtfPx.getText()));
        p.setOrdonnee(Double.parseDouble(this.jtfPy.getText()));
    }
}
